module Timer(CLOCK_50, ADDMIN, ADDHOUR, FULLSEC, SECOND, DECASEC, MINUTE, DECAMIN, HOUR, DECAHOUR, RESET);
	input CLOCK_50, ADDMIN, ADDHOUR, RESET;
	output [5:0] FULLSEC; //full binary seconds (for clock)
	output [3:0] SECOND, DECASEC, MINUTE, DECAMIN, HOUR;
	output [1:0] DECAHOUR;
	
	wire clk = CLOCK_50;
	
	reg [25:0] CountToCentiSec = 26'd0;
	reg [25:0] CountToSecond = 26'd0;
	reg [5:0] CountFullSecs = 6'd0;
	reg [3:0] CountSecs = 4'd0;
	reg [3:0] CountDecaSecs = 4'd0;
	reg [3:0] CountMins = 4'd0;
	reg [3:0] CountDecaMins = 4'd0;
	reg [3:0] CountHours = 4'd0;
	reg [1:0] CountDecaHours = 2'd0;
	
	//wire sigcentisec = (CountToCentiSec == 499999);
	//wire sigsec = (sigcentisec && (CountToCentiSec == 99));
	wire sigsec = (CountToSecond == 49999999);
	wire sigdecasec = (sigsec && (CountSecs == 9));
	wire sigmin = (sigsec && (CountFullSecs == 59)) || ADDMIN;
	wire sigdecamin = (sigmin && (CountMins == 9));
	wire sighour = (sigmin && (CountDecaMins == 5) && (CountMins == 9)) || ADDHOUR;
	wire sigdecahour = (sighour && (CountHours == 9));
	wire sigday = (sighour && (CountHours == 3) && (CountDecaHours == 2));
	
	always @(posedge clk) begin
		/*if(sigcentisec)
			CountToCentiSec <= 0;
		else
			CountToCentiSec <= CountToCentiSec + 1;*/
	
		if(sigsec)
			CountToSecond <= 0;
		else //if(sigcentisec)
			CountToSecond <= CountToSecond + 1;
		
		if(sigdecasec)
			CountSecs <= 0;
		else if (sigsec)
			CountSecs <= CountSecs + 1;

		if (sigmin)
			CountDecaSecs <= 0;
		else if (sigdecasec)
			CountDecaSecs <= CountDecaSecs + 1;
			
		if (sigmin)
			CountFullSecs <= 0;
		else if (sigsec)
			CountFullSecs <= CountFullSecs + 1;
			
		if(sigdecamin)
			CountMins <= 0;
		else if(sigmin)
			CountMins <= CountMins + 1;
		
		if (sighour && !ADDHOUR)
			CountDecaMins <= 0;
		else if (sigdecamin)
			CountDecaMins <= CountDecaMins + 1;
			
		if (sigdecahour)
			CountHours <= 0;
		else if(sighour)
			CountHours <= CountHours + 1;
			
		if(sigday) begin
			CountDecaHours <= 0;
			CountHours <= 0;
		end
		else if (sigdecahour)
			CountDecaHours <= CountDecaHours + 1;
			
		if(RESET) begin
			CountToCentiSec <= 0;
			CountToSecond <= 0;
			CountSecs <= 0;
			CountDecaSecs <= 0;
			CountFullSecs <= 0;
			CountMins <= 0;
			CountDecaMins <= 0;
			CountHours <= 0;
			CountDecaHours <= 0;
		end
	end
	
	assign FULLSEC = CountFullSecs;
	assign SECOND = CountSecs;
	assign DECASEC = CountDecaSecs;
	assign MINUTE = CountMins;
	assign DECAMIN = CountDecaMins;
	assign HOUR = CountHours;
	assign DECAHOUR = CountDecaHours;

endmodule